package com.liuhouse.controller;

import com.liuhouse.service.OssUploadService;
import com.liuhouse.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

//上传文件
@RestController
public class UploadController {

    @Autowired
    private OssUploadService uploadService;

    /**
     * 写博文,上传文件
     * @param multipartFile   上传的文件信息
     * @return
     */
    @PostMapping("/upload")
    public ResponseResult uploadImg(@RequestParam("img") MultipartFile multipartFile){
        try {
            return uploadService.uploadImg(multipartFile);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException("上传文件失败");
        }
    }

}
